﻿using System;
using System.Windows;

using Buddy.Common.Plugins;
using Buddy.Swtor;

namespace Buddywing.Plugins
{
    public class OpenLockboxesPlugin : IPlugin
    {
        #region Implementation of IEquatable<IPlugin>

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(IPlugin other)
        {
            return other.Name == Name;
        }

        #endregion

        #region Implementation of IPlugin

        public string Author { get { return "Apoc"; } }

        public Version Version { get { return new Version(0, 1); } }

        public string Name { get { return "Use Lockboxes"; } }

        public string Description { get { return "Opens any lockboxes within your inventory. This is for collecting credits from them!"; } }

        public Window DisplayWindow { get { return null; } }

        private DateTime LastChecked { get; set; }

        /// <summary> Executes the pulse action. This is called every "tick" of the bot. </summary>
        public void OnPulse()
        {
            // Don't run in combat.
            //if (BuddyTor.Me.InCombat)
             //   return;

            // Only every 10s.
            if(DateTime.Now.Subtract(LastChecked).TotalSeconds > 10)
            {

                foreach (Buddy.Swtor.Objects.TorEffect o in BuddyTor.Me.CurrentTarget.Debuffs) { Buddy.Common.Logging.Write("Name: " + o.Name + " Guid: " + o.Guid + " Caster: " + o.Caster.Name + " Time Left: " + o.TimeLeft + " " + o.Duration + " " + o.EffectNumber); }
                LastChecked = DateTime.Now;
                foreach (var o in BuddyTor.Me.InventoryEquipment)
                {
                    if(o.Name.Contains("Credit Box") || o.Name.Contains("Credit Case"))
                        o.Use();
                }
            }
        }

        /// <summary> Executes the initialize action. This is called at initial bot startup. (When the bot itself is started, not when Start() is called) </summary>
        public void OnInitialize()
        {
        }

        /// <summary> Executes the shutdown action. This is called when the bot is shutting down. (Not when Stop() is called) </summary>
        public void OnShutdown()
        {
        }

        /// <summary> Executes the enabled action. This is called when the user has enabled this specific plugin via the GUI. </summary>
        public void OnEnabled()
        {
        }

        /// <summary> Executes the disabled action. This is called whent he user has disabled this specific plugin via the GUI. </summary>
        public void OnDisabled()
        {
        }

        #endregion
    }
}
